package rannablesafe;


class SaleTicket1 implements Runnable{
    int ticket  = 100;
    boolean flag = true;
    @Override
    public void run() {
        while(flag) {
           show();
        }

    }

    public synchronized void show(){

        try{
            Thread.sleep(30);
        }catch (Exception e){
            e.printStackTrace();
        }
        if (ticket > 0) {
            System.out.println(Thread.currentThread().getName() + "票号为：" + ticket);
            ticket--;
        } else {
            flag = false;
        }
    }
}
public class WindowTest1 {
    public static void main(String[] args) {
        SaleTicket1 s = new SaleTicket1();

        Thread t1 = new Thread(s);
        Thread t2 = new Thread(s);
        Thread t3 = new Thread(s);

        t1.setName("窗口一");
        t2.setName("窗口二");
        t3.setName("窗口三");

        t1.start();
        t2.start();
        t3.start();


    }
}
